package com.ibm.cps.redis;

import com.ibm.util.LocalConfig;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

public class GeneralRedis {
	private String redisHost;
	private int redisPort;
	private JedisPool pool;
	private Jedis connection;
	private static GeneralRedis redis = null;

	public static GeneralRedis getGeneralRedis() {
		if (redis == null)
			redis = new GeneralRedis(LocalConfig.REDIS_SERVER_HOST,
					LocalConfig.REDIS_SERVER_PORT);

		return redis;
	}

	public GeneralRedis(String redisHost, int redisPort) {
		this.redisHost = redisHost;
		this.redisPort = redisPort;
		pool = new JedisPool(new JedisPoolConfig(), redisHost, redisPort);
	}

	public void flushKeys() {
		connection = pool.getResource();
		connection.flushDB();
		pool.returnResource(connection);
	}
}
